export const chooseImage = (config) => {
	const {count = 1} = config || {};
	let apiName = 'chooseImage';
	// #ifdef MP-WEIXIN
	apiName = 'chooseMedia'
	// #endif
	return new Promise((resolve,reject) => {
		uni[apiName]({
			count,
			mediaType: ['image'],
			sizeType: ['compressed'],
			success: res => {
				console.log(res,'ress')
				// #ifdef MP-WEIXIN
				const tempFilePaths = res.tempFiles;
				resolve(tempFilePaths.map(item => item.tempFilePath))
				// #endif
				// #ifdef H5
				const files = res.tempFiles;
				resolve({files,blobPath: res.tempFilePaths})
				// #endif
				// #ifndef MP-WEIXIN || H5
				const tempFilePaths = res.tempFilePaths;
				resolve(tempFilePaths)
				// #endif
				
			},
			fail: err => {
				reject()
			}
		})
	})
}
//手机号验证
export const isPhone = (val) => {
	const reg = /^(1)[0-9]{10}$/;
	return reg.test(val.trim())
}
export const imageToBase64 = (file) => {
	console.log(file)
	return new Promise((resolve,reject) => {
	// #ifdef H5
		const fileReader = new FileReader();
		fileReader.onload = () => {
			const srcData = fileReader.result.split('base64,')[1];
			resolve({base64: srcData, path: file.path})
		  };
		  fileReader.readAsDataURL(file);
	// #endif
	// #ifdef MP-WEIXIN
	const manager = uni.getFileSystemManager();
	manager.readFile({
		filePath: file,
		encoding: 'base64',
		success: res => {
			resolve({base64: res.data, path:file})
		}
	})
	// #endif
	})
}